const map = new WeakMap()
const ob = new ResizeObserver((entries) => {
  
  for (const entry of entries) {
    const handler = map.get(entry.target);
    handler && handler({
      width: entry.borderBoxSize[0].inlineSize,
      height: entry.borderBoxSize[0].blockSize
    } as {
      width: number,
      height: number
    });
  }
});

export default {
  mounted(el: HTMLElement, binding: any) {
    map.set(el, binding.value);
    ob.observe(el);
  },
  unmounted(el: HTMLElement) {
    ob.unobserve(el);
  },
};
